﻿@using System.Data.Linq
@using System.Web.UI.WebControls
@using DistanceLearning.Controllers
@using DistanceLearning.Models

@Html.DevExpress().GridView(
    settings =>
        {
        settings.Name = "testListGrid";
        settings.CallbackRouteValues = new { Controller = "ExamTest", Action = "MainPagePartial" };
        settings.Width = Unit.Percentage(100);

        var controller = ViewContext.Controller as JournalBaseController;
        settings.Columns.Add(column =>
                                 {
            column.Caption = "#";
            column.SetDataItemTemplateContent(c =>
            {
                
                if(controller.UserKind == UserKind.Admin || controller.UserKind == UserKind.SchoolAdmin)
                {
                    ViewContext.Writer.Write(
                    Html.ActionLink("Редактировать", "EditingEdit", new {ExamTestID = DataBinder.Eval(c.DataItem, "ExamTestID")}) + "&nbsp;" +
                    Html.ActionLink("Удалить", "EditingDelete", new {examTestId = DataBinder.Eval(c.DataItem, "ExamTestID")},
                                    new {onclick = "return confirm('Вы действительно хотите удалить тест со всеми вопросами и результатами?')"})// + "&nbsp;"
                                    );
                }
                ViewContext.Writer.Write(
                    @Html.ActionLink("Пройти тест", "RunTest", new {testId = DataBinder.Eval(c.DataItem, "ExamTestID")}));

            });
            if (controller.UserKind == UserKind.Admin || controller.UserKind == UserKind.SchoolAdmin || controller.UserKind == UserKind.Teacher)
            {
                column.SetHeaderTemplateContent(c =>
                {
                    ViewContext.Writer.Write(
                        Html.ActionLink("Новый", "EditingEdit", new { examTestId = -1 }).ToHtmlString());
                });
            }
            column.Settings.AllowDragDrop = DefaultBoolean.False;
            column.Settings.AllowSort = DefaultBoolean.False;
            column.Width = 70;
        });
                    
        settings.Columns.Add(column => {
            column.FieldName = "Subject.SubjectName";
            column.Caption = "Предмет";
        });
        settings.Columns.Add("TestName", "Название теста");
        //settings.Columns.Add("ExamTestQuestions.Count", "Количество вопросов");

        if (controller.UserKind == UserKind.Admin || controller.UserKind == UserKind.SchoolAdmin || controller.UserKind == UserKind.Teacher)
        {
            settings.Columns.Add(column =>
            {
                column.SetDataItemTemplateContent(c =>
                {
                    ViewContext.Writer.Write(
                        @Html.ActionLink("Добавить вопрос", "CreateOpenQuestion", new { testID = DataBinder.Eval(c.DataItem, "ExamTestID") }) + "&nbsp;" +
                        @Html.ActionLink("Добавить закрытый вопрос", "CreateClosedQuestion", new { testID = DataBinder.Eval(c.DataItem, "ExamTestID") })
                    );
                });
                column.Settings.AllowDragDrop = DefaultBoolean.False;
                column.Settings.AllowSort = DefaultBoolean.False;
                column.Width = 60;
            });
        }

        settings.SettingsPager.PageSize = 50;
        //settings.Settings.ShowFilterRow = true;
        //settings.Settings.ShowFilterRowMenu = true;
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ClearFilterButton.Visible = true;
    }).Bind(Model).GetHtml()